<template>
  <el-dialog v-if="load" :close-on-click-modal="false" title="批量修改默认品牌" v-model="visible" append-to-body width="500px" @close="handleClose">
    <el-form label-position="top">
      <el-form-item label="默认品牌">
        <VSelect v-model="form.brand_ids" placeholder="请选择" :options="options.brand" multiple collapse-tags
            class="w-full" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">关 闭</el-button>
      <el-button type="primary" :loading="loadings.submit" @click="submit">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import api from '../api'
import { ElMessage } from 'element-plus'
const props = defineProps({
  options: { type: Object, default: () => ({}) },
})

const load = ref(false)
const visible = ref(false)
let loadings = reactive({})
const form = ref({})

const emit = defineEmits(['close', 'success'])

// 打开弹窗
const open = async (shop_ids) => {
  form.value = { shop_ids }
  if (!load.value) {
    load.value = true
    await 1
  }
  loadings = reactive({})
  visible.value = true
}
// 关闭弹窗
const close = () => {
  visible.value = false
}

const handleClose = () => {
  emit('close')
}
// 提交
const submit = () => {
  loadings.submit = true
  api.editBrand(form.value).then(res => {
    ElMessage.success('操作成功')
    emit('success')
    close()
  }).finally(() => {
    loadings.submit = false
  })
}

defineExpose({ open })
</script>